﻿using System;
using System.Collections.Generic;

namespace Ex1Student
{
    class Student
    {
        private string name;
        private int age;
        private int grade;
        private bool male;
        private int ssn;
        private static HashSet<int> allSSN = new HashSet<int>();
        private DateTime dateOfBirth;
        
        public int Ssn
        {
            get
            {
                return ssn;
            }
            set
            {
                if (value.ToString().Length!=9)
                {
                    throw new InvalidStudentException("The SSN number is exaclty 9 numbers");
                } if (allSSN.Contains(ssn))
                {
                    throw new InvalidStudentException("A student with this SSN is already defined !");
                }
                allSSN.Add(ssn);
                ssn = value;
            }
        }

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                if (value.Length < 10 || value.Length > 50)
                {
                    throw new InvalidStudentException("Name should be between 10 and 50.");
                }
                name = value;
            }
        }

        public int Age
        {
            get
            {
                return age;
            }
            set
            {
                if (value < 7 || value > 18)
                {
                    throw new InvalidStudentException("Age should be between 7 and 18.");
                }
                age = value;
            }
        }

        public int Grade
        {
            get
            {
                return grade;
            }
            set
            {
                if (value < 1 || value > 11)
                {
                    throw new InvalidStudentException("Grade should be between 1 and 11.");
                }
                grade = value;
            }
        }

        public bool Male
        {
            get
            {
                return male;
            }
            set
            {
                male = value;
            }
        }

        public DateTime DateOfBirth
        {
            get
            {
                return dateOfBirth;
            }
            set
            {
                if (value.Year<1900||value.Year>2010)
                {
                    throw new InvalidStudentException("BirthDate should be between 1900 and 2011");
                }
                dateOfBirth = value;
            }
        }

        public Student(string name, int age, int grade, bool male,int ssn)
        {
            this.Name = name;
            this.Age = age;
            this.Grade = grade;
            this.Male = male;
            this.Ssn = ssn;
        }
    }

    public class InvalidStudentException : ApplicationException
    {
        public InvalidStudentException(string msg)
            : base(msg)
        {

        }
    }
}
